<style lang="less" scoped>
.panel {
  margin-bottom: 10px;
  &-title {
    display: flex;
    padding: 10px;
    border-bottom: 0.1px solid #eaeaea;
    background: white;

    &__label {
      flex: 1;
      font-size: 16px;
      align-items: center;
    }
  }
  &-content {
    margin-bottom: 10px;
    background: white;
    display: flex;

    &__dec {
      flex: 1;
    }
    &__arrow {
      display: flex;
      align-items: center;
    }
    &__item {
      display: flex;
      padding: 10px 10px 0 10px;
      font-size: 14px;
      &-label {
        color: #666;
      }
      &-value {
        flex: 1;
        padding-left: 15px;
        color: #333;
      }
    }
  }
}
</style>

<template>
  <div class="panel">
    <template v-for="(item, index) in items" wx:key="unique">
      <!-- title -->
      <!-- <div class="panel-title" :key="'title'+index">
          <div class="panel-title__label" v-html="item.Title||'-'"></div>
          <div class="panel-title__right"></div>
        </div> -->
      <!-- content -->
      <div class="panel-content" :key="'content'+index" @click="itemClick(item.Id)">
        <div class="panel-content__dec">
          <div class="panel-content__item">
            <div class="panel-content__item-label c-primary">{{item.CaseNo||'-'}}</div>
            <div class="panel-content__item-value"></div>
            <div class="panel-content__item-right"></div>
          </div>
          <div class="panel-content__item">
            <div class="panel-content__item-label">违法类型</div>
            <div class="panel-content__item-value">{{item.IllegalType||'-'}}</div>
            <div class="panel-content__item-right"></div>
          </div>
          <div class="panel-content__item">
            <div class="panel-content__item-label">处罚单位</div>
            <div class="panel-content__item-value">{{item.PunishGov||'-'}}</div>
            <div class="panel-content__item-right"></div>
          </div>
          <div class="panel-content__item">
            <div class="panel-content__item-label">处罚日期</div>
            <div class="panel-content__item-value">{{item.PunishDate||'-'}}</div>
            <div class="panel-content__item-right"></div>
          </div>
        </div>
        <div class="panel-content__arrow">
          <i class="iconfont icon-more"></i>
        </div>
      </div>
    </template>

    <!-- search on loading -->
    <load v-if="loading" />

    <!-- 无数据 -->
    <div class="info" v-else-if="items.length===0||(items.length!==0&&totalPage===pageIndex)">无更多数据</div>
  </div>
</template>
<script>
import Load from '@/components/load';
export default {
  components: { Load },
  computed: {
    loading() {
      return this.$store.getters.loading;
    }
  },
  data() {
    return {
      items: [],
      TotalRecords: 0, //总条数
      totalPage: 0, // 总页数，默认为0
      pageIndex: 1 //当前页码，默认为1
    };
  },
  onLoad() {
    this.getInfos();
  },
  onUnload() {
    // 清除数据缓存
    this.items = [];
  },
  onReachBottom() {
    // 上拉加载
    if (!this.loading && this.pageIndex < this.totalPage) {
      this.search(this.pageIndex + 1);
    }
  },
  methods: {
    async getInfos(pageIndex = 1) {
      // 获取列表信息
      if (typeof pageIndex !== 'number') {
        pageIndex = 1;
      }
      if (pageIndex === 1) {
        this.items = [];
      }

      // 查询
      const url = '/xcx/getEnvPunishmentList';
      let unique = '';
      try {
        unique = this.$root.$mp.page.options.Unique;
      } catch (error) {}

      const params = {
        unique,
        pageIndex
      };
      const { status, message, result } = await this.$http.get(url, params);
      if (status !== 200) {
        wx.showToast({
          title: message || '查询失败！',
          icon: 'none',
          duration: 2000
        });
        return;
      }

      //更新数据
      if (pageIndex === 1) {
        this.items = result.Result;
      } else {
        this.items = [...this.items, ...result.Result];
      }

      //更新分页信息
      try {
        this.pageIndex = pageIndex;
        const page = result.Paging.TotalRecords / result.Paging.PageSize;
        this.totalPage = Math.ceil(page);
        this.TotalRecords = result.Paging.TotalRecords;
      } catch (error) {
        this.totalPage = 0;
      }
    },

    itemClick(id) {
      // 路由跳转
      this.$router.push({
        path: './detail/main',
        query: { id }
      });
    }
  }
};
</script>
